/**
 * @summary 文章请求模块
 */

import req from '@/utils/request';
import * as URL from '@/constants/api';

/**
 * @param { string } id
 * @returns
 * @summary 关注
 */
export function follow(id) {
  return req({
    url: URL.FOLLOW,
    method: 'post',
    data: {
      target: id,
    },
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message));
}

/**
 * @param { object } params mobile & code
 * @returns
 * @summary 登录
 */
export function login(params) {
  return req({
    url: URL.LOGIN,
    method: 'post',
    data: params,
  })
    .then(res => {
      // 记token
      localStorage.setItem('TOKEN', `Bearer ${res.data.data.token}`);
      return res.data.message
    })
    .catch(err => Promise.reject(err.response.data.message));
}
